﻿/////////////////////////////////////////////////////////////////
//File: Factory.cs
//Description:  
//            
//Copyright© 2011 Moliu
//History:
//  2011-3-26 18:11:20    MoLiu    Original Version
/////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Security.Permissions;
using MAF.Common;
using MAF.Common.Security;
using My.Blog.Domain.Entities;
using My.Blog.Domain.Interfaces;
using My.Blog.Business.Persistence;
using My.Blog.Business.Security;

namespace My.Blog.Business.Service
{
    /// <summary>
    /// 创建组合业务类，这些类组织了所有业务功能，供用户界面调用
    /// </summary>
    public partial class BizFactory : IFactory
    {
        private BizFactory(){}
        private static IFactory _Instance = null;
        public static IFactory Instance
        {
            get 
            {
                if (null == _Instance)
                    _Instance = new BizFactory();
                return _Instance;
            }
        }

        private string _daoConfFileName = ConfigurationManager.AppSettings["DaoConfFileName"];

        public IBlog CreateBlog()
        {
            return new BlogSafe(new BlogSvc());
        }

        public ICategory CreateCategory()
        {
            return new CategorySafe(new  CategorySvc());
        }

        public IArticle CreateArticle()
        {
            return new ArticleSafe(new ArticleSvc());
        }

        public IComment CreateComment()
        {
            return new CommentSafe(new CommentSvc());
        }

        public IFile CreateFile()
        {
            return new FileSafe(new FileSvc());
        }
    }

    /// <summary>
    /// 创建数据访问（Dao）类，这些类仅仅有数据访问的功能，专供本程序集除数据访问层外的其他层次调用
    /// </summary>
    internal class DaoFactory : IFactory
    {
        private DaoFactory() { }
        private static IFactory _Instance = null;
        public static IFactory Instance
        {
            get 
            {
                if (null == _Instance)
                    _Instance = new DaoFactory();
                return _Instance;
            }
        }

        private static string _daoConfFileName = ConfigurationManager.AppSettings["DaoConfFileName"];

        public IBlog CreateBlog()
        {
            return new BlogDao(_daoConfFileName);
        }

        public ICategory CreateCategory()
        {
            return new CategoryDao(_daoConfFileName);
        }

        public IArticle CreateArticle()
        {
            return new ArticleDao(_daoConfFileName);
        }

        public IComment CreateComment()
        {
            return new CommentDao(_daoConfFileName);
        }

        public IFile CreateFile()
        {
            return new FileDao(_daoConfFileName);
        }
    }
}
